package com.xzj.admin.resource.sync.service.impl;

import com.xzj.admin.resource.sync.domain.vo.SelectOption;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import com.xzj.common.datasource.domain.PageReq;
import com.xzj.common.datasource.domain.PageResp;
import com.xzj.common.datasource.utils.XzjPageUtil;
import com.xzj.admin.resource.sync.domain.entity.ResFieldsManage;
import com.xzj.admin.resource.sync.mapper.ResFieldsManageMapper;
import com.xzj.admin.resource.sync.service.ResFieldsManageService;

import java.util.List;

/**
 * @program: xzj-admin
 * @ClassName: ResFieldsManageServiceImpl
 * @description: 资源字段管理;(res_fields_manage)表服务实现类
 * @author: XiaZunJun
 * @create: 2024-10-31
 */
@Service
public class ResFieldsManageServiceImpl implements ResFieldsManageService{
    @Resource
    private ResFieldsManageMapper resFieldsManageMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param fieldId 主键
     * @return 实例对象
     */
    public ResFieldsManage queryById(String fieldId){
        return resFieldsManageMapper.queryById(fieldId);
    }

    /**
     * 分页查询
     *
     * @param pageReq 分页筛选条件对象
     * @return 查询结果
     */
    public PageResp<ResFieldsManage> pageQuery(PageReq<ResFieldsManage> pageReq){
        return XzjPageUtil.queryPage(pageReq, resFieldsManage -> resFieldsManageMapper.pageQuery(resFieldsManage));
    }

    /**
     * 新增数据
     *
     * @param resFieldsManage 实例对象
     * @return 实例对象
     */
    public ResFieldsManage insert(ResFieldsManage resFieldsManage){
        resFieldsManageMapper.insert(resFieldsManage);
        return resFieldsManage;
    }

    /**
     * 更新数据
     *
     * @param resFieldsManage 实例对象
     * @return 实例对象
     */
    public ResFieldsManage update(ResFieldsManage resFieldsManage){
        resFieldsManageMapper.update(resFieldsManage);
        return resFieldsManage;
    }

    /**
     * 通过主键删除数据
     *
     * @param fieldId 主键
     * @return 是否成功
     */
    public boolean deleteById(String fieldId){
        int total = resFieldsManageMapper.deleteById(fieldId);
        return total > 0;
    }

    @Override
    public List<SelectOption> queryByResId(String sourceId) {
        return resFieldsManageMapper.queryByResId(sourceId);
    }
}